<template>
    <el-dialog close-on-press-escape draggable :close-on-click-modal="false" :modal="true" align-center destroy-on-close
        v-model="store.dialog.form.show" :title="store.dialog.form.title" width="1400">
        <!-- <div style="width: 100%;max-height: calc(100vh - 300px);overflow-y: auto;">
            <cform :disabled="1" :form="store.dialog[props.formIndex].form" :value="store.dialog[props.formIndex].value"
                @change="(e) => {
                    console.log(e)
                }"></cform>
        </div>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="handleClose">取消</el-button>
                <el-button @click="handleOK" type="primary">
                    确定
                </el-button>
            </div>
        </template> -->
        <div style="width: 100%;height: auto;">
            <div v-if="store.dialog.form.controls && store.dialog.form.controls.length" style="padding: 4px 0;">
                <cControls :data="store.dialog.form.controls"></cControls>
            </div>
            <div style="width: 100%;height: calc(80vh - 80px);overflow-y: auto;">
                <cform :read-mode="store.dialog.form.readMode" :disabled="store.dialog.form.disabled" @change="(e, fm) => {
                    value = e
                    form = fm
                    try {
                        store.dialog.form.changeCallBack(e, fm)
                    } catch (error) {

                    }
                }" style="width: 100%;height: 100%;" :form="store.dialog.form.form" :value="store.dialog.form.value">
                </cform>
            </div>
            <flexBox style="margin-top: 5px;width: 100%;" justify-content="flex-end" gap="8px">
                <el-button @click="() => {
                    try {
                        store.dialog.form.cancelCallBack(value, form)
                        store.hideFormDialog()
                    } catch (error) {
                        tool.toast.error(`${error}`)
                    }
                }" v-if="store.dialog.form.showCancel" style="margin: 0;">取消</el-button>
                <el-button @click="() => {
                    try {
                        store.dialog.form.okCallBack(value, form)
                    } catch (error) {
                        tool.toast.error(`${error}`)
                    }
                }" style="margin: 0;" type="primary">确定</el-button>
            </flexBox>
        </div>
    </el-dialog>
</template>

<script setup>
import { ref, reactive, defineProps, computed, watch, onMounted, onBeforeUnmount } from 'vue'
import { useStore } from '../modules/store';
const store = useStore()
import flexBox from './flexBox.vue'
import cform from './cForm.vue';
import cControls from './cControls.vue';
import tool from '../modules/tool'

const value = ref({})

const form = ref([])

onMounted(async () => {

})

</script>

<style scoped></style>